package com.hsy.linemoney.modules.my.editinformation;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hsy.linemoney.R;
import com.hsy.linemoney.modules.common.CommonBaseActivityWithSimpleActionBar;
import com.hsy.linemoney.utils.CommonUtils;

/**
 * Created by Administrator on 2016/7/12.
 */
public class EditAddressActivity extends CommonBaseActivityWithSimpleActionBar {

    private EditText address_edit, xi_address_edit;
    private TextView address_edit_line, xi_address_edit_line;
    private LinearLayout edit_btn;
    private String province = "", city = "";

    @Override
    public boolean onActionBarRightButtonClicked(ImageButton rightButton) {
        finish();
        return super.onActionBarRightButtonClicked(rightButton);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle(R.string.title_my_edit_address);
        setRightButtonVisiblity(View.VISIBLE);
        setRightButtonText(getString(R.string.my_edit_common_right_save));
        setContentView(R.layout.activity_edit_address);
        setRightButtonTextColor(R.color.common_white);

        address_edit_line = F(R.id.address_edit_line);
        address_edit = F(R.id.address_edit);
        editTextLine(address_edit, address_edit_line);

        xi_address_edit_line = F(R.id.xi_address_edit_line);
        xi_address_edit = F(R.id.xi_address_edit);
        editTextLine(xi_address_edit, xi_address_edit_line);


        edit_btn = F(R.id.edit_btn);
        edit_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(SelectProvinceActivity.class);
            }
        });


    }

    @Override
    protected void onResume() {
        super.onResume();
        province = CommonUtils.getProvince(this);
        city = CommonUtils.getCity(this);
        if ("".equals(province) || "".equals(city)) {

        } else {
            address_edit.setText(province + " " + city);
        }
    }

    private void editTextLine(EditText editText, final TextView line) {
        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    line.setBackgroundDrawable(getResources().getDrawable(R.color.color_action_bar_bg));
                } else {
                    line.setBackgroundDrawable(getResources().getDrawable(R.color.line));
                }
            }
        });

    }

}
